]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
status/network: Tie wireless network items to their network
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Wed, 29 Apr 2026 17:06:43 +0000 (19:06 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 13 Sep 2026 17:39:10 +0000 (19:39 +0200)
We were using a map to control the wireless networks and relate them to
the associated item, although we did not clean it up fully on destruction.

So rather than handling the manual removal of the items bound to a
wireless network, tie them to the network destruction itself.

This allows to simplify the removal of an access point, by just
destroying its network and to avoid using a sub-utilized Map.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4203>
(cherry picked from commit 51f2d834395d1066b54a33d32d487e1716fd8943)

js/ui/status/network.js

index 4c28690b326939128335546ab694c5d3c0d8674e..1bc9d402a88f82bd416410bd127e6aa0f7f9d60c 100644 (file)
@@ -1083,7 +1083,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
 
         this._deviceName = '';
 
-        this._networkItems = new Map();
+        this._networks = [];
         this._itemSorter = new ItemSorter({
             sortFunc: (one, two) => one.network.compare(two.network),
         });
@@ -1124,10 +1124,8 @@ const NMWirelessDeviceItem = GObject.registerClass({
         this._availableConnectionsChanged();
         this._updateItemsVisibility();
 
-        this.connect('destroy', () => {
-            for (const net of this._networkItems.keys())
-                net.destroy();
-        });
+        this.connect('destroy',
+            () => this._networks.forEach(net => net.destroy()));
     }
 
     get icon_name() {
@@ -1219,8 +1217,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
 
     _availableConnectionsChanged() {
         const connections = this._device.get_available_connections();
-        for (const net of this._networkItems.keys())
-            net.checkConnections(connections);
+        this._networks.forEach(net => net.checkConnections(connections));
     }
 
     _addAccessPoint(ap) {
@@ -1236,8 +1233,7 @@ const NMWirelessDeviceItem = GObject.registerClass({
             return;
         }
 
-        let network = [...this._networkItems.keys()]
-            .find(n => n.checkAccessPoint(ap));
+        let network = this._networks.find(n => n.checkAccessPoint(ap));
 
         if (!network) {
             network = new WirelessNetwork(this._device);
@@ -1248,28 +1244,30 @@ const NMWirelessDeviceItem = GObject.registerClass({
             network.connectObject(
                 'notify::icon-name', () => this._resortItem(item),
                 'notify::is-active', () => this._resortItem(item),
+                'destroy', () => {
+                    const idx = this._networks.indexOf(network);
+                    if (idx >= 0)
+                        this._networks.splice(idx, 1);
+
+                    this._itemSorter.delete(item);
+                    item.destroy();
+                },
                 this);
 
             const pos = this._itemSorter.upsert(item);
             this.section.addMenuItem(item, pos);
-            this._networkItems.set(network, item);
+            this._networks.push(network);
         }
 
         network.addAccessPoint(ap);
     }
 
     _removeAccessPoint(ap) {
-        const network = [...this._networkItems.keys()]
-            .find(n => n.removeAccessPoint(ap));
+        const network = this._networks.find(n => n.removeAccessPoint(ap));
 
         if (!network || network.hasAccessPoints())
             return;
 
-        const item = this._networkItems.get(network);
-        this._itemSorter.delete(item);
-        this._networkItems.delete(network);
-
-        item?.destroy();
         network.destroy();
     }